package com.yyy.config;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import com.yyy.config.validate.MySqlValidate;

public class MyWebApplicationInitializer implements WebApplicationInitializer {

	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		
	    AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
	    webContext.register(SpringMvcConfig.class);
	    webContext.register(MySqlValidate.class);
	    webContext.register(PersistenceContext.class);
	    
		ServletRegistration.Dynamic registration = servletContext.addServlet("spring-mvc",
				new DispatcherServlet(webContext));
		
		registration.setLoadOnStartup(1);
		registration.addMapping("/");

	}
}
